package com.annoton;


import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class Person {

    @Deprecated
    @MyAnnotation
    public void empty() {
        System.out.println("empty");
    }

    @MyAnnotation(value = {"ding", "jia"})
    public void showContent(String value, int intValue) {
        System.out.println(value + " " + intValue);
    }
}

public class AnnoTest1 {

    public static void main(String[] argv) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Person person = new Person();

        Class<Person> c = Person.class;

        Method mEmpty = c.getMethod("empty", new Class[]{});
        mEmpty.invoke(person, new Object[]{});
        parseAnnotation(mEmpty);

        Method mShow = c.getMethod("showContent", new Class[]{String.class, int.class});
        mShow.invoke(person, new Object[]{"ding", 35});
        parseAnnotation(mShow);

    }

    public static void parseAnnotation(Method method) {
        if (method.isAnnotationPresent(MyAnnotation.class)) {
            MyAnnotation myAnnotation = method.getAnnotation(MyAnnotation.class);
            String[] values = myAnnotation.value();
            for (String str : values) {
                System.out.println(str);
            }

            Annotation[] annotations = method.getAnnotations();
            for (Annotation annotation : annotations) {
                System.out.println(annotation);
            }
        }

        System.out.println("----------------------------------");
    }
}
